package com.drinks.yiniang.utils;

import android.view.Gravity;
import android.widget.Toast;

import com.drinks.yiniang.App;

/**
 * Created by han on 16/10/9.
 */
public class ToastUtils {

    private static Toast toast;

    /**
     * 短时间显示Toast
     *
     * @param message
     */
    public static void showShort(CharSequence message) {
        if(message == null) {
            return;
        }

        if (toast == null) {
            toast = Toast.makeText(App.getInstance().getApplicationContext(), "", Toast.LENGTH_SHORT);
        } else {
            toast.setDuration(Toast.LENGTH_SHORT);
        }

        toast.setText(message);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 短时间显示Toast
     *
     * @param resId
     */
    public static void showShort(int resId) {
        if(resId <= 0) {
            return;
        }

        if (toast == null) {
            toast = Toast.makeText(App.getInstance().getApplicationContext(), "", Toast.LENGTH_SHORT);
        } else {
            toast.setDuration(Toast.LENGTH_SHORT);
        }

        toast.setText(resId);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 长时间显示Toast
     *
     * @param message
     */
    public static void showLong(CharSequence message) {
        if(message == null) {
            return;
        }

        if (toast == null) {
            toast = Toast.makeText(App.getInstance().getApplicationContext(), "", Toast.LENGTH_LONG);
        } else {
            toast.setDuration(Toast.LENGTH_LONG);
        }

        toast.setText(message);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 长时间显示Toast
     *
     * @param resId
     */
    public static void showLong(int resId) {
        if(resId <= 0) {
            return;
        }

        if (toast == null) {
            toast = Toast.makeText(App.getInstance().getApplicationContext(), null, Toast.LENGTH_LONG);
        } else {
            toast.setDuration(Toast.LENGTH_LONG);
        }

        toast.setText(resId);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}
